home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: regmia@ix.netcom.com
- Newsgroups: comp.lang.c++
- Subject: Re: Help on assignment
- Date: Wed, 21 Feb 1996 06:47:43 GMT
- Organization: Netcom
- Message-ID: <4gef32$6g7@reader2.ix.netcom.com>
- References: <4gdmjm$1kr@cloner4.netcom.com>
- NNTP-Posting-Host: ix-lv3-20.ix.netcom.com
- X-NETCOM-Date: Tue Feb 20 10:45:54 PM PST 1996
- X-Newsreader: Forte Free Agent 1.0.82
-
- dc30@ix.netcom.com(Diane Cogswell ) wrote:
-
- >I'm hoping someone out there can help me out. I just started c++ and
- >I'm having problems with a couple assinments. Don't think I recieved
- >enough information.
- >The first one:
- >Write a function that normally takes one argument, the address of a
- >string, and prints that string once. However, if a second, type int
- >argument is provided and is greater than zero, the function prints the
- >string the number of times equal to the number of times indicated.
-
- >Second one is
- >Write a function called zerosmaller that is passed to two int arguments
- >by reference and then sets the smaller of the two numbers to 0. Write a
- >main() program to exercise this function and print out the result.
- >I would really appreciate any help anyone can give me. I understood
- >Pascal but I'm having trouble trying to translate programs in c++.
- >Thanks
- > from discouraged
-
-
- Ok you declare your first function like so:
-
- void printstring(char *thestring, int count = 0);
-
- The 'count = 0' is a default, if no parameter is sent
- to it, count defaults to 0 (Zero) or if a parameter is
- sent to it, count equals that value.
- ex. printstring (MyName); ---- count equals Zero
- ex printstring (MyName, 5); --- count equals 5
-
-
- Ok you declare your second function like so:
-
- void zerosmaller(int *firstnum, int *secondnum);
-
- if actual code for this function would look like this:
-
-
- void zerosmaller (int* firstnum, int* secondnum)
- {
- /* Check to see if they are even */
- if (*firstnum == *secondnum)
- return;
-
- /* Find which is smaller then change its value to Zero */
- if (*firstnum < *secondnum)
- *firstnum = 0;
- else
- *secondnum = 0;
- }
-
-
-
- void main()
- {
- #include <iostream.h>
-
- int a,b;
-
- a = 7;
- b = 2;
- cout <<"Before zerosmaller:"<<a<<" "<<b<<'\n';
- zerosmaller(&a, &b);
- cout <<"After zerosmaller:" <<a<<" "<<b<<'\n';
-
-
- }
-
-
- I Hope that works for you guy :)
-
-
-